package com.Q02;

import com.common.ListNode;

/**
 * @version v1.0.0
 * 创建时间：2022/6/24 10:14
 */
public class Q02_05 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        int enter = 0;
        ListNode i=l1,j = l2;
        ListNode res = new ListNode(-1);
        ListNode trueHead = res;
        while(i!=null&&j!=null){
            int temp = i.val + j.val + enter;
            enter = temp/10;
            res.next = new ListNode(temp%10);
            res = res.next;
            i = i.next;
            j = j.next;
        }

        while(i!=null){
            int temp = i.val + enter;
            enter = temp/10;
            res.next = new ListNode(temp%10);
            res = res.next;
            i = i.next;
        }
        while(j!=null){
            int temp = j.val + enter;
            enter = temp/10;
            res.next = new ListNode(temp%10);
            res = res.next;
            j = j.next;
        }
        return trueHead.next;
    }

    public static void main(String[] args) {
        new Q02_05().addTwoNumbers(new ListNode(7,new ListNode(1,new ListNode(6))),new ListNode(5,new ListNode(9,new ListNode(2))));
    }
}
